package Xuanke;

public class Student {
    private int studentId;
    private String studentName;
    private String major;

    private String studentSex;
    private Course[] courses;

    public Student() {
        super();
        courses = new Course[1];
    }
    public Student(int studentId,String studentName) {
        super();
        this.studentId=studentId;
        this.studentName=studentName;
        courses = new Course[1];
    }
    public Student(int studentId,String studentName,String major) {
        super();
        this.studentId=studentId;
        this.studentName=studentName;
        this.major = major;
        courses = new Course[1];
    }

    //修改获取属性name,id,major
        public int getStudentId() {
            return studentId;
        }
        public void setStudentId(int studentId) {
            this.studentId = studentId;
        }
        public String getStudentName() {
            return studentName;
        }

        public void setStudentName(String studentName) {
            this.studentName = studentName;
        }

        public String getMajor() {
            return major;
        }
        public void setMajor(String major) {
            this.major = major;
        }

    //学生选课；
    public boolean addCourse(Course course){
        boolean flag=false;
        for(int i=0;i<this.courses.length;i++){
            if(courses[i]==null){
                courses[i]=course;
                course.addStudent(this);//课程也要添加学生
                flag=true;
                break;
            }
        }
        return flag;
    }
    //学生移除课程
    public boolean removeCourse(Course course){
        boolean flag=false;
        for(int i=0;i<this.courses.length;i++){
            if(courses[i]==course){
                courses[i]=null;
                course.removeStudent(this);//在课程中移除学生
                flag=true;
                break;
            }
        }
        return flag;
    }
    //显示学生所选的课程
    public void displayCourse(){
        System.out.println("学生"+this.studentName+"所选课程有：");
        for(Course c:courses){
            if(c!=null){
                System.out.print(c.getName()+" ");
            }
        }
        System.out.println();
    }

}
